package com.guoteng.androidlearn;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

public class CommonUIActivity extends BaseActivity implements Button.OnClickListener {

    private static final String TAG = "CommonUIActivity";
    private EditText editText;
    private ImageView imageView;
    private ProgressBar progressBar;

    public static void startActivity(Context context) {

        Intent intent = new Intent(context, CommonUIActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_common_ui);


        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(this);

        editText = (EditText) findViewById(R.id.edit_text);

        imageView = (ImageView) findViewById(R.id.image_view);

        progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.button: {

                String inputText = editText.getText().toString();

                Toast.makeText(getApplicationContext(), inputText, Toast.LENGTH_SHORT).show();

                imageView.setImageResource(R.drawable.meinv002);

//                if (progressBar.getVisibility() == View.VISIBLE) {
//
//                    progressBar.setVisibility(View.GONE);
//                }else {
//
//                    progressBar.setVisibility(View.VISIBLE);
//                }

                if (progressBar.getProgress() < 100) {
                    progressBar.setProgress(progressBar.getProgress() + 10);
                }


                Log.d(TAG, "按钮点击, onClick");
                break;
            }

            default:
                break;
        }
    }


    public void showAlert(View v) {

        AlertDialog.Builder alert = new AlertDialog.Builder(CommonUIActivity.this);
        alert.setTitle("alert标题");
        alert.setMessage("您好！你需要这些东西吗？");
        alert.setCancelable(false);
        alert.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                Log.d(TAG, "选择确定");
            }
        });

        alert.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                Log.d(TAG, "选择取消");
            }
        });

        alert.show();
    }

    public void showProgressDialog(View v) {

        ProgressDialog dialog = new ProgressDialog(CommonUIActivity.this);

        dialog.setCancelable(true);
        dialog.setTitle("我的标题");
        dialog.setMessage("我的提示内容");

        dialog.show();

    }

}
